﻿// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.

#ifndef CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_
#pragma once

#include "include/base/cef_scoped_ptr.h"
#include "include/base/cef_thread_checker.h"
#include "include/cef_app.h"
#include "include/cef_command_line.h"
#include "tests/cefclient/browser/main_context.h"
#include "tests/cefclient/browser/root_window_manager.h"

namespace client {

// Used to store global context in the browser process.
class MainContextImpl : public MainContext {
 public:
	 enum AppModel
	 {
		 gallery = 0,  //壁纸商店  gallery store
		 login = 1,   //登录   login
		 comment = 2,   //评论     comment
		 capture = 3,      //抓屏     screen capture
		 webplayer = 4,    //壁纸播放    wallpaper player
		 aftersome = 5,  // 番剧aftersome player     
		 widget = 6,    // 小组件视频预览
		 newtab = 7,    // 未使用
		 paper= 8,     //  壁纸控件模式     
		 userdetail = 9 , // 用户详情      userdetail
		 cinema = 10,  // 2.0新番剧     new aftersome
		 userguide = 11  // 用户引导视频播放   user guide video player
 	 };

  MainContextImpl(CefRefPtr<CefCommandLine> command_line,
                  bool terminate_when_all_windows_closed);

  // MainContext members.
  std::string GetConsoleLogPath() OVERRIDE;
  std::string GetDebugLogPath() OVERRIDE;
  std::string GetDownloadPath(const std::string& file_name) OVERRIDE;
  std::string GetAppWorkingDirectory() OVERRIDE;
  std::string GetMainURL() OVERRIDE;
  cef_color_t GetBackgroundColor() OVERRIDE;
  CefRect GetBound() OVERRIDE;
  void SaveBoundRect(CefRect & r) OVERRIDE;
  HWND GetCallerHwnd() OVERRIDE;
  void SaveRootHandler(HWND handler) OVERRIDE;
  void SaveLoginPopupHandler(HWND handler) OVERRIDE;
  HWND GetLoginPopupHandler() OVERRIDE;
  HWND GetRootHandler() OVERRIDE;
  //void SaveLoginToken(std::string t) OVERRIDE;
  //std::string  GetLoginToken() OVERRIDE;
  void SaveAppModel(int model) OVERRIDE;
  int GetAppModel() OVERRIDE;
  bool IsGalleryApp() OVERRIDE;
  bool IsLoginApp()  OVERRIDE;
  bool IsUserDetailApp() OVERRIDE;
  bool IsCommentApp()  OVERRIDE;
  bool IsCaptureApp() OVERRIDE;
  bool IsWebplayerApp() OVERRIDE;
  bool IsAfterSomeApp() OVERRIDE;
  bool IsWidgetApp() OVERRIDE;
  bool IsNewTabApp()  OVERRIDE;
  bool IsPaperApp()  OVERRIDE;
  bool IsCinemaApp() OVERRIDE;
  bool IsUserGuideApp() OVERRIDE;
  bool IsFullScreen() OVERRIDE;
  int GetScreenId() OVERRIDE;
  CefString  GetAppName()  OVERRIDE;
  CefString GetWinClassName() OVERRIDE;
  std::string GetJsFilePath() OVERRIDE;
  CefString GetJsDirectory() OVERRIDE;
  void SaveURootUrl(std::string url) OVERRIDE;
  std::string GetURootUrl() OVERRIDE;
  void SaveCommentDetailUrl(std::string url) OVERRIDE;
  std::string GetCommentDetailUrl() OVERRIDE;
  std::string GetAttachUrl() OVERRIDE;
  float  GetDpiScale() OVERRIDE;
  void SaveDpiScale(float scale) OVERRIDE;
  void SaveShowStatus(bool) OVERRIDE;
  bool IsShow() OVERRIDE;
  int GetTabId() OVERRIDE;
  void SaveTabId(int id) OVERRIDE;
  std::vector<CefString> &  GetClientIdentify()  OVERRIDE;
  void SavePopupType(int type) OVERRIDE;
  int GetPopupType()  OVERRIDE;
  void SavePopupParentWindow(HWND h) OVERRIDE;
  HWND GetPopupParentWindow() OVERRIDE;
  CefString GetDetailURL() OVERRIDE;
  CefString& GetPaperDirectory() OVERRIDE;
  std::string &GetDomainUrl() OVERRIDE;
  std::string &GetIndexUrl() OVERRIDE;
  std::string GetCollectionUrl() OVERRIDE;
  std::string GetBuckUrl()  OVERRIDE;
  std::string GetLoginUrl() OVERRIDE;
  std::string GetUserUrl() OVERRIDE;
  CefString GetFaviratePath() OVERRIDE;
  CefString GetAnimeDetailFlag() OVERRIDE;
  CefString GetFirstUrl() OVERRIDE;
  std::string GetPageidUrl() OVERRIDE;
  int GetInitVolume() OVERRIDE;
  int GetInitPlayModel() OVERRIDE;
  int GetInitWebPage() OVERRIDE;
  CefString GetInitPlayingId() OVERRIDE;
  long GetDownloadSpeed()  OVERRIDE;
  std::string GetAnimateUrl() OVERRIDE;
  CefString GetPidFromUrl() OVERRIDE;
  std::string GetNewMsgNum() OVERRIDE;
  std::string GetMsgOpen() OVERRIDE;
  void ClearPidFromUrl();

  bool UseViews() OVERRIDE;
  bool UseWindowlessRendering() OVERRIDE;
  void PopulateSettings(CefSettings* settings) OVERRIDE;
  void PopulateBrowserSettings(CefBrowserSettings* settings) OVERRIDE;
  void PopulateOsrSettings(OsrRenderer::Settings* settings) OVERRIDE;
  RootWindowManager* GetRootWindowManager() OVERRIDE;

  // Initialize CEF and associated main context state. This method must be
  // called on the same thread that created this object.
  bool Initialize(const CefMainArgs& args,
                  const CefSettings& settings,
                  CefRefPtr<CefApp> application,
                  void* windows_sandbox_info);

  // Shut down CEF and associated context state. This method must be called on
  // the same thread that created this object.
  void Shutdown();

 private:
  // Allow deletion via scoped_ptr only.
  friend struct base::DefaultDeleter<MainContextImpl>;

  ~MainContextImpl();

  // Returns true if the context is in a valid state (initialized and not yet
  // shut down).
  bool InValidState() const { return initialized_ && !shutdown_; }

  // parse upuoo url config fiel
 void parseupupooconfig();
 void parseAnimateConfig();

  CefRefPtr<CefCommandLine> command_line_;
  const bool terminate_when_all_windows_closed_;

  // Track context state. Accessing these variables from multiple threads is
  // safe because only a single thread will exist at the time that they're set
  // (during context initialization and shutdown).
  bool initialized_;
  bool shutdown_;

  std::string main_url_;
  cef_color_t background_color_;
  cef_color_t browser_background_color_;
  bool use_windowless_rendering_;
  bool use_views_;
  CefRect  cef_rect_;
  HWND   caller_hwnd_;
  HWND   root_hwnd_;
  HWND login_popup_hwnd_;
  HWND  login_base_hwnd_;
  std::string user_token_;
  int  app_model_;
  bool full_screen_;
  int screenid_;
  std::string js_file_;
  std::string urooturl_;
  std::string comment_detail_url_;
  std::string attachurl_;
  float  dipscale_;
  bool  showstatus_;
  int  tabindex_;
  std::vector<CefString> client_identify_;
  int popup_type_;
  HWND popup_login_rootwindow_;
  CefString  detail_url_;
  CefString paper_path;
  CefString  upupoo_config_path_;
  std::string index_url_;
  std::string animate_url_;
  std::string   root_url_;
  std::string collection_url;
  std::string  bucket_url_;
  std::string login_url_;
  std::string  user_url_;
  CefString favirate_path_;
  CefString js_directory_;
  CefString detail_flag_;
  CefString first_url_;
  std::string pageid_url_;
  int volume_;
  int playmodel_;
  int webpage_;
  CefString  playingid_;
  long download_speed_;
  CefString detail_pid_;
  std::string  new_msg_num_;
  std::string  open_msg_;

  scoped_ptr<RootWindowManager> root_window_manager_;

  // Used to verify that methods are called on the correct thread.
  base::ThreadChecker thread_checker_;

  DISALLOW_COPY_AND_ASSIGN(MainContextImpl);
};

class WebUrl {
	      public:
			  WebUrl(const  std::string& url) : _url(url) { }
			  WebUrl(std::string&& url) : _url(move(url)) { }
			  std::string Request(const std::string& request) const;
		  private:
			  std::string _url;
			 
};

}  // namespace client

#endif  // CEF_TESTS_CEFCLIENT_BROWSER_MAIN_CONTEXT_IMPL_H_
